﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Bussiness.Service;

namespace Bussiness.View.BackEnd
{
    public partial class MG_Catelogies_Product : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            Appcontex app = (Appcontex)Session["app"];
            if(app.IsAdmin == false){
                Button3.Visible = false;
                Button4.Visible = false;
            }
            loadData();
        }

        public void save_CatelogiesParent(object sender, DirectEventArgs e)
        {
            CateloriesProduct catelogy = new CateloriesProduct();
            catelogy.Name = dmChaTen.Text;
            catelogy.Description = dmConMoTa.Text;
            //catelogy.IsSize = isSize.Checked;
            new Catelogy_Service().save_Catelogy_Product(catelogy);
            MessageBox msg = new MessageBox();
            msg.Alert(" ", "Lưu thành công");
            msg.Show();
        }
        public void save_CatelogiesChild(object sender, DirectEventArgs e)
        {
            CateloriesProduct catelogy = new CateloriesProduct();
            catelogy.Name = dmConTen.Text;
            catelogy.Description = dmConMoTa.Text;
            catelogy.ParentId = int.Parse(SLDMCha_Grid.SelectedItem.Value);
            new Catelogy_Service().save_Catelogy_Product(catelogy);
            MessageBox msg = new MessageBox();
            msg.Alert(" ", "Lưu thành công");
            msg.Show();
        }

        public void delete(int id)
        {

        }

        public void loadData()
        { 
            //load data selectbox danh muc cha
            SLDMCha_Store.DataSource = new Catelogy_Service().getCateloriesProductParent();
            SLDMCha_Store.DataBind();
            //load data grid danh muc cha
            DSDMCha_Store.DataSource = new Catelogy_Service().getCateloriesProductParent();
            DSDMCha_Store.DataBind();
            //load data grdi danh muc con
            DSDMCon_Store.DataSource = new Catelogy_Service().getAllCatelogiesProductChild();
            DSDMCon_Store.DataBind();
        }
    }
}
